package taller2.controller.listeners;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import taller2.interfaces.HidableWindow;
import taller2.view.menus.CodeBrowser;
import taller2.view.menus.CodeMenu;

public class WindowClosingListener implements WindowListener{
	private HidableWindow parent;
	private CodeBrowser browser;
	private CodeMenu menu;
	
	// constructor
	public WindowClosingListener(HidableWindow window){
		this.parent = window;
		window.setVisible(false);
		
		this.browser = null;
		this.menu = null;
	}
	
	public void setBrowser(CodeBrowser browser){
		this.browser = browser;
	}

	@Override
	public void windowActivated(WindowEvent arg0) {
	}

	@Override
	public void windowClosed(WindowEvent arg0) {
		parent.setVisible(true);
		
		if(browser != null)
			browser.stopAutoscroll();
		if(menu != null)
			menu.setAutohighlightButton(false);
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		parent.setVisible(true);
		
		if(browser != null)
			browser.stopAutoscroll();
		if(menu != null)
			menu.setAutohighlightButton(false);
	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {	
	}

	@Override
	public void windowIconified(WindowEvent arg0) {	
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
	}

	public void setMenu(CodeMenu menu) {
		this.menu = menu;
	}
	
}
